using System;
using System.Web.UI;
using SharpPieces.Web.Controls;
using System.Drawing;
using System.Web;
using SharpPieces.Web;

namespace SharpPieces.DemoApp
{

    /// <summary>
    /// The Gradient Button Appearance demo page.
    /// </summary>
    public partial class GradientBtnAppearance : Page
    {

        // Methods

        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load"/> event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs"/> object that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (!this.IsPostBack)
            {
                // hover effect for GradientButton12

                this.GradientButton12.GradientBackground.GradientStartColor = ColorTranslator.FromHtml("#949494");
                this.GradientButton12.GradientBackground.GradientEndColor = ColorTranslator.FromHtml("#505050");

                // preload the image to get an instant hover effect

                this.ClientScript.RegisterClientScriptBlock(
                    this.GetType(),
                    string.Format("{0}PreLoadHover", this.GradientButton12.ClientID),
                    string.Format("if (document.images) {{ new Image().src='{0}'; }};", Util.AppRelativeToAbsolute(this.GradientButton12.Src, false)),
                    true);

                this.GradientButton12.Attributes["onmouseover"] =
                    string.Format("this.src='{0}';", this.GradientButton12.Src);

                this.GradientButton12.GradientBackground.GradientStartColor = ColorTranslator.FromHtml("#848484");
                this.GradientButton12.GradientBackground.GradientEndColor = ColorTranslator.FromHtml("#404040");

                this.GradientButton12.Attributes["onmouseout"] =
                    string.Format("this.src='{0}';", this.GradientButton12.Src);
            }
        }

        /// <summary>
        /// Handles the Click event of the GradientButton controls.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">
        /// The <see cref="System.EventArgs"/> instance containing the event data.
        /// </param>
        protected void GradientButton_Click(object sender, EventArgs e)
        {
            if (sender is GradientButton)
            {
                this.Label1.Text =
                    string.Format("The '{0}' gradient button was clicked at {1} server time.",
                        (sender as GradientButton).Text.Value, DateTime.Now.ToLongTimeString());
            }
        }

    }

}
